package com.ado.bazinga.core.assemble;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Component;

import com.ado.bazinga.core.common.params.vo.GoodVO;
import com.ado.bazinga.core.dal.entity.Good;

/**
 *@author adonais
 *@date 2020年4月4日
 *@description GoodAssemble.java  Good 装配器
**/
@Component(value = "goodAssemble")
public class GoodAssemble {
	
	/***
	 * 
	 * @param good
	 * @return
	 */
	public GoodVO assembleToVo(Good good) {
		GoodVO goodVo = new GoodVO() ;
		goodVo.setId(good.getId().toString());
		goodVo.setIntroduction(good.getIntroduction());
		goodVo.setName(good.getName());
		goodVo.setOriginalPrice(good.getOriginalPrice().toString());
		goodVo.setPic(good.getPic());
		goodVo.setPresentPrice(good.getPresentPrice().toString());
		goodVo.setSold(good.getSold().toString());
		goodVo.setStock(good.getStock().toString());
		goodVo.setType(good.getType());
		return goodVo ;
	}
	
	/***
	 * 批量转换
	 * @return
	 */
	public List<GoodVO> assembleBatchToVo(List<Good> goodList ) {
		List<GoodVO> goodVOs = new ArrayList<GoodVO>() ;
		if (goodList.size() > 0) {
			for (Good good : goodList) {
				GoodVO goodVo = new GoodVO() ;
				goodVo.setId(good.getId().toString());
				goodVo.setIntroduction(good.getIntroduction());
				goodVo.setName(good.getName());
				goodVo.setOriginalPrice(good.getOriginalPrice().toString());
				goodVo.setPic(good.getPic());
				goodVo.setPresentPrice(good.getPresentPrice().toString());
				goodVo.setSold(good.getSold().toString());
				goodVo.setStock(good.getStock().toString());
				goodVo.setType(good.getType());
				goodVOs.add(goodVo) ;
			}
		}
		return goodVOs ;
	}

}
